package com.wc.算法提高课.A第一章_动态规划.数位DP.不要62;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/5/24 15:58
 * @description
 * https://www.acwing.com/problem/content/1087/
 */
public class Main {
    /**
     * 思路：灵神
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 15, M = 10;
    static int[][] f = new int[N][M];
    static int[] nums = new int[N];
    static int L, R;

    public static void main(String[] args) {
        while (sc.hasNext()) {
            L = sc.nextInt();
            R = sc.nextInt();
            if (L == 0) break;
            out.println(dp(R) - dp(L - 1));
        }
        out.flush();
    }

    static int dp(int x) {
        for (int i = 0; i < N; i++) Arrays.fill(f[i], -1);
        int len = 1;
        while (x > 0) {
            nums[len++] = x % 10;
            x /= 10;
        }
        return dfs(len - 1, -1, true, false);
    }

    static int dfs(int i, int j, boolean limit, boolean num) {
        if (!limit && num && f[i][j] >= 0) return f[i][j];
        if (i == 0) return num ? 1 : 0;

        int up = limit ? nums[i] : 9;
        int res = 0;
        for (int d = 0; d <= up; d++) {
            if (j == 6 && d == 2 || d == 4) continue;
            res += dfs(i - 1, d, limit && d == up, num || d > 0);
        }

        if (!limit && num) f[i][j] = res;

        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

